package com.javabasic.algorithm.leetcode;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/1/29 20:44
 * @Version 1.0
 **/
public class RemoveDuplicatesFromSortedArray {

    public static void main(String[] args) {

    }

    public int removeDuplicates(int[] nums) {
        if (nums.length < 2) return nums.length;
        int pre = nums[0];
        int len = nums.length;
        int tag = -1;
        for (int i = 1; i < len; i++) {
            if (nums[i] != pre) {
                if (tag != -1) {
                    nums[tag] = nums[i];
                    tag++;
                }
            } else if (tag == -1) {
                tag = i;
            }
            pre = nums[i];
        }
        System.out.println(tag);
//        for (int i = 0; i < len / 2; i++) {
//            int temp = nums[i];
//            nums[i] = nums[len-1-i];
//            nums[len-1-i] = temp;
//        }
        return tag == -1 ? nums.length:tag;
    }
}
